package com.cj.cms.template;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cj.common.utils.AppInfo;

public class ThreadExecutorPool {
	protected static Logger logger = LoggerFactory.getLogger(ThreadExecutorPool.class);
    //线程池大小
    private int poolSize = 2;  
    private ExecutorService service;
    public ExecutorService getService() {  
        return service;  
    }  
  
    public int getPoolSize() {  
        return poolSize;  
    }  
  
    public void setPoolSize(int poolSize) {  
        this.poolSize = poolSize;  
    }
    
    private ThreadExecutorPool() {
    	try {
    		poolSize = Integer.valueOf(AppInfo.get("poolSize")).intValue();
		} catch (Exception e) {
			logger.error("初始化email线程错误!",e);
		}        
		service = Executors.newFixedThreadPool(poolSize);  
	}

	private static class Holder {
		public static ThreadExecutorPool instance = new ThreadExecutorPool();
	}

	public static ThreadExecutorPool getInstance() {
		return Holder.instance;
	}
}
